const date = require('../../utils/date');

/**
 * @class SafeDatetime
 * @param { string } time   输入时间字符串
 */
class SafeDatetime {
    constructor(time) {
        let value;
        try {
            value = time ? new Date(time) : new Date();
        } catch (error) {
            throw new RangeError(`Expected time string, got ${typeof time}`);
        }
        this.value = date.toLocaleString(value);
    }
}

module.exports = SafeDatetime;